/*
 * @Description:数据字典
 */
import { get, post } from '@/utils/http';
import {
  IDictTypeItem,
  IDictParams,
  IDictItemResult,
  ICreateDict,
  ILocationParams,
  ILocationItemResult,
  IAddLocation,
  ITagType,
  IHandleTagType
} from './model/dataDictModel';
import { BasicPagingListResult } from '@/apis/basicModel';

enum Api {
  // 字典类型列表
  GET_LIST_TYPE_DICT = '/upms/systemDictType/list',
  // 分页查询数据字典
  GET_LIST_DICT_PAGE = '/upms/systemDict/page',
  // 添加数据字典类型
  ADD_DICT_TYPE = '/upms/systemDictType/create',
  EDIT_DICT_TYPE = '/upms/systemDictType/update',
  DEL_DICT_TYPE = '/upms/systemDictType/delete',
  ADD_DICT = '/upms/systemDict/create',
  EDIT_DICT = '/upms/systemDict/update',
  DEL_DICT = '/upms/systemDict/delete',
  // 修改字典启用状态
  UPDATE_STATUS = '/upms/systemDict/updateStatus',
  // 根据数据类型查询字典列表
  GET_DICT_BY_TYPE = '/upms/systemDict/getByTypeAndGroup',
  // 查询地区列表
  GET_LOCATION_LIST = '/upms/location/list',
  // 添加地区
  ADD_LOCATION = '/upms/location/create',
  EDIT_LOCATION = '/upms/location/update',
  DEL_LOCATION = '/upms/location/deleteByCode',
  // 地域标签 - 获取所有地域标签列表
  GET_LOCATION_TAG_LIST = '/upms/locationTag/list',
  // 地域标签 - 分页获取地域标签
  LOCATION_TAG__PAGE_LIST = '/upms/locationTag/pageList',
  // 地域标签 - 删除地域标签（可批量）
  BATCH_DELETE_TAG = '/upms/locationTag/delete',
  // 地域标签 - 修改地域标签
  EDIT_LOCATION_TAG = '/upms/locationTag/update',
  // 地域标签 - 新增地域标签
  ADD_LOCATION_TAG = '/upms/locationTag/create'
}

// 字典类型列表
export const getDictTypeList = (): Promise<IDictTypeItem[]> => get(Api.GET_LIST_TYPE_DICT);
export const getDictListPage = (
  params: IDictParams
): Promise<BasicPagingListResult<IDictItemResult>> => get(Api.GET_LIST_DICT_PAGE, params);

export const createDict = (params: ICreateDict) => post(Api.ADD_DICT, params);
export const editDict = (params: ICreateDict) => post(Api.EDIT_DICT, params);

export const removeDict = (id: string) => post(Api.DEL_DICT, { id });
export const getDictByType = (dataGroup: string, dataType: string): Promise<IDictItemResult[]> =>
  get(Api.GET_DICT_BY_TYPE, { dataGroup, dataType });

export const updateStatusDict = (id: string, enableFlag: boolean) =>
  post(Api.UPDATE_STATUS, { id, enableFlag });

export const getLocationList = (params: ILocationParams): Promise<ILocationItemResult[]> =>
  get(Api.GET_LOCATION_LIST, params);

export const addLocation = (params: IAddLocation) => post(Api.ADD_LOCATION, params);
export const editLocation = (params: IAddLocation) => post(Api.EDIT_LOCATION, params);
export const delLocation = (code: string) => post(Api.DEL_LOCATION, { code });

// 地域标签 - 获取所有地域标签列表
export const getLocationTagList = () => get(Api.GET_LOCATION_TAG_LIST, {});
// 地域标签 - 分页获取地域标签
export const getLocationTagPageList = (params: any): Promise<ITagType[]> =>
  get(Api.LOCATION_TAG__PAGE_LIST, params);
// 地域标签 - 删除地域标签（可批量）
export const batchDeleteTag = (params: { tagIdList: string[] }) =>
  post(Api.BATCH_DELETE_TAG, params);
// 地域标签 - 修改地域标签
export const editLocationTag = (params: IHandleTagType) => post(Api.EDIT_LOCATION_TAG, params);
// 地域标签 - 新增地域标签
export const addLocationTag = (params: IHandleTagType) => post(Api.ADD_LOCATION_TAG, params);
